import request from '@/utils/request';

const orderModel = {
  namespace: 'order',
  state: {
    orderList: [],
    orderDetail: {},
    searchState: {},
    total: 0,
    pageNum: 1,
    pageSize: 10
  },
  effects: {
    *init(_, {call, put, select}){
      const {code, data: {records: data = [], total = 0} = {}} = yield call(() => request('/api1/monitorDevice/orderPageList'));
      // console.log('DDD2', data2);
      if (code && code === 200){
        yield put({
            type: 'setState',
            payload: {
              orderList: [],
              total
            }
        })
      }
    },
    *getDetail({payload}, {call, put}){
      const {id} = payload;
      const {code, data = {}} = yield call(() => request.get('/api1/monitorDevice/orderById', {params: {id}}));
      console.log('DDD', data);
      if (code && code === 200){
        yield put({
          type: 'setState',
          payload: {
            orderDetail: data
          }
        })
      }
    }
  },
  reducers: {
    setState(state, {payload}){
      return {
        ...state,
        ...payload
      }
    }
  }
};
export default orderModel;
